package middlewareLogExtraction.model;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RecordFactory {
	private static final String loginPattern = "login:valid user - (.*)$";
	private static final String SPTimingPattern = "timing\\s+(GBL[^\\s]*)\\s+([\\d|m]+.\\d+s)";
	private static final String productPattern = "GBL2092\\s+SPPARMS\\s+.*:SG:([^:]*):.*";

	public static Record createRecord(String text, RegexHelper regexHelper) {
		Matcher matcher = null;
		if((matcher = regexHelper.regexFind(text, loginPattern)) != null){
			return new LoginRecord(matcher.group(1));
		}
		if((matcher = regexHelper.regexFind(text, SPTimingPattern)) != null){
			return new SPTimingRecord(matcher.group(1), matcher.group(2));
		}
		if((matcher = regexHelper.regexFind(text, productPattern)) != null){
			return new ProductRecord(matcher.group(1));
		}
		return null;
	}

}
